package cn.edu.hust.sse.software7.class3.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hust.sse.software7.class3.entities.EBCommonOnProduct;
import cn.edu.hust.sse.software7.class3.entities.EBProduct;
import cn.edu.hust.sse.software7.class3.service.EBProductService;
import cn.edu.hust.sse.software7.class3.serviceImpl.EBCommonOnProductServiceImpl;
import cn.edu.hust.sse.software7.class3.serviceImpl.EBProductServiceImpl;

public class GoServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String page = req.getParameter("page");
		if(page.equals("regist")){
			HttpSession session = req.getSession();
			session.removeAttribute("message");
			resp.sendRedirect("eBusiness/user/regist.jsp");
		}
		if(page.equals("watchprods")){
			EBProductService ebps = new EBProductServiceImpl();
			List<EBProduct> prods = ebps.getProds();
			HttpSession session = req.getSession();
			session.setAttribute("prodList", prods);
			resp.sendRedirect("eBusiness/prod/watchProds.jsp");
		}
		if(page.equals("watchProdDetail")){
			String prod2Watch = req.getParameter("prod2Watch");
			HttpSession session = req.getSession();
			Long prodId = new Long(prod2Watch);
			EBProductService ebps = new EBProductServiceImpl();
			EBProduct ebp = ebps.getProdById(prodId);
			session.setAttribute("watchProd", ebp);
			List<EBCommonOnProduct> ebcop = new EBCommonOnProductServiceImpl()
					.getCommonsByProductId(prodId);
			session.setAttribute("prodCommonList", ebcop);
			resp.sendRedirect("eBusiness/prod/WatchProdDetail.jsp");
		}
		
	}

}
